package com.ghck.shop.utils;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;

import com.ghck.server.model.FriendTreatmentPic;
import com.ghck.server.model.Friends;
import com.ghck.server.model.TreatmentPic;
import com.ghck.server.model.Users;
import com.ghck.server.model.response.SimpleUserProfileRes;


public class FileStoreUtil {
	private final static Logger logger = LoggerFactory.getLogger(FileStoreUtil.class);
	private static Environment env;
	
	public void setEnv(Environment env) {
		FileStoreUtil.env = env;
	}
	
	public static Environment getEnv(){
		return env;
	}
	
	public static String getBaseUrl(){
		//String baseUrl = env.getProperty("config.base_url").concat(env.getProperty("config.ext_res"));
		String baseUrl = env.getProperty("config.base_url");
		return baseUrl;
	}
	
	public static void dealWithAvatar(Users user){
		if(!StringUtils.isEmpty(user.getAvatar()) && !StringUtils.startsWithIgnoreCase(user.getAvatar(), "http")){
			user.setAvatar(FileStoreUtil.getBaseUrl()+user.getAvatar());
		}
	}
	public static void dealWithAvatar(Friends user){
		if(!StringUtils.isEmpty(user.getAvatar()) && !StringUtils.startsWithIgnoreCase(user.getAvatar(), "http")){
			user.setAvatar(FileStoreUtil.getBaseUrl()+user.getAvatar());
		}
	}
	public static void dealWithAvatar(SimpleUserProfileRes user){
		if(!StringUtils.isEmpty(user.getAvatar()) && !StringUtils.startsWithIgnoreCase(user.getAvatar(), "http")){
			user.setAvatar(FileStoreUtil.getBaseUrl()+user.getAvatar());
		}
	}
	public static void dealWithTreatmentPic(TreatmentPic treatmentPic){
		if(!StringUtils.isEmpty(treatmentPic.getPath()) && !StringUtils.startsWithIgnoreCase(treatmentPic.getPath(), "http")){
			treatmentPic.setPath(FileStoreUtil.getBaseUrl()+treatmentPic.getPath());
		}
	}
	
	public static void dealWithTreatmentPic(FriendTreatmentPic treatmentPic){
		if(!StringUtils.isEmpty(treatmentPic.getPath()) && !StringUtils.startsWithIgnoreCase(treatmentPic.getPath(), "http")){
			treatmentPic.setPath(FileStoreUtil.getBaseUrl()+treatmentPic.getPath());
		}
	}
}